/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

package com.zr.coverflow.slice;

import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Text;
import ohos.hiviewdfx.HiLog;
import ohos.hiviewdfx.HiLogLabel;


import java.util.ArrayList;

import me.crosswall.coverflow.demo.ResourceTable;
import me.crosswall.lib.coverflow.PageSliderAdapter;
import me.crosswall.lib.coverflow.view.PagerContainer;

/**
 * TwoViewpageabilityslice
 *
 * @since 2021-03-26
 */
public class TwoViewpageabilityslice extends AbilitySlice {
    private static final HiLogLabel LABEL_LOG = new HiLogLabel(HiLog.LOG_APP, 0, "TwoViewpageabilityslice");
    PagerContainer pageslider1;
    PagerContainer pageslider2;
    private Text textView;
    private Text textView2;
    private ArrayList<Integer> arrayList;
    private  String item = "Item";

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_twoviewpage_layout);
        arrayList = new ArrayList<>();
        arrayList.add(ResourceTable.Media_color_0);
        arrayList.add(ResourceTable.Media_harcolor1);
        arrayList.add(ResourceTable.Media_harcolor2);
        arrayList.add(ResourceTable.Media_harcolor3);
        arrayList.add(ResourceTable.Media_harcolor4);
        arrayList.add(ResourceTable.Media_harcolor5);
        arrayList.add(ResourceTable.Media_harcolor6);
        arrayList.add(ResourceTable.Media_harcolor7);
        arrayList.add(ResourceTable.Media_harcolor8);
        arrayList.add(ResourceTable.Media_harcolor9);
        arrayList.add(ResourceTable.Media_harcolor10);
        arrayList.add(ResourceTable.Media_harcolor11);
        arrayList.add(ResourceTable.Media_harcolor12);
        arrayList.add(ResourceTable.Media_harcolor13);
        arrayList.add(ResourceTable.Media_harcolor14);
        initview();
        initdata();
    }

    private void initview() {
        pageslider1 = (PagerContainer) findComponentById(ResourceTable.Id_pageslider1);
        pageslider2 = (PagerContainer) findComponentById(ResourceTable.Id_pageslider2);
        textView = (Text) findComponentById(ResourceTable.Id_TextView);
        textView2 = (Text) findComponentById(ResourceTable.Id_TextView2);
    }

    /**
     * initdata
     */
    public void initdata() {
        PageSliderAdapter bannerAdapter = new PageSliderAdapter(arrayList, getContext());
        pageslider1.setPageadapter(bannerAdapter);
        pageslider1.setCurrpage(0);
        PageSliderAdapter bannerAdapter1 = new PageSliderAdapter(arrayList, getContext());
        pageslider2.setPageadapter(bannerAdapter1);
        pageslider2.setCurrpage(0);
        PagerContainer.PageItemClickListener onSelectListener1 = new PagerContainer.PageItemClickListener() {
            @Override
            public void onItemClick(int index) {
                pageslider1.setCurrpage(index);
                textView.setText(item + index);
                pageslider2.setCurrpage(index);
                textView2.setText(item + index);
            }

            @Override
            public void onPageSliding(int i2, float v1, int i1) {
            }
        };
        pageslider1.setPageItemClickListener(onSelectListener1);
        PagerContainer.PageItemClickListener onSelectListener2 = new PagerContainer.PageItemClickListener() {
            @Override
            public void onItemClick(int index) {
                pageslider1.setCurrpage(index);
                textView.setText(item + index);
                pageslider2.setCurrpage(index);
                textView2.setText(item + index);
            }

            @Override
            public void onPageSliding(int i2, float v1, int i1) {
            }
        };
        pageslider2.setPageItemClickListener(onSelectListener2);
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}
